package graduate.cslg.com.universityshopping.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import graduate.cslg.com.universityshopping.R;
import graduate.cslg.com.universityshopping.entity.LostCardBean;

public class LostInfoAdapter extends RecyclerView.Adapter<LostInfoAdapter.ViewHolder> {

    private Context mContext;
    private List<LostCardBean> mLostCardBeans;

    public class ViewHolder extends RecyclerView.ViewHolder {

        private TextView cardAccount;
        private TextView cardName;
        private TextView pickTel;

        public ViewHolder(View itemView) {
            super(itemView);
            cardAccount = itemView.findViewById(R.id.card_account);
            cardName = itemView.findViewById(R.id.card_name);
            pickTel = itemView.findViewById(R.id.pick_tel);
        }
    }

    public LostInfoAdapter(List<LostCardBean> lostCardBeans) {
        mLostCardBeans = lostCardBeans;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (mContext == null) {
            mContext = parent.getContext();
        }
        View view = LayoutInflater.from(mContext).inflate(R.layout.layout_lost_info_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        LostCardBean lostCardBean = mLostCardBeans.get(position);
        holder.cardAccount.setText(lostCardBean.getCard_account());
        holder.cardName.setText(lostCardBean.getCard_name());
        holder.pickTel.setText(lostCardBean.getUser_tel());
    }

    @Override
    public int getItemCount() {
        return mLostCardBeans.size();
    }
}
